//
//  SubjectThreeLightSetViewController.m
//  CoachsBook
//
//  Created by MaBookPro on 2022/8/24.
//

#import "SubjectThreeLightSetViewController.h"
#import "SubjectThreeLightCell.h"
#import "CustomDirectiveViewController.h"

static NSString *headidentifir = @"headview";
@interface SubjectThreeLightSetViewController ()<UICollectionViewDelegate,UICollectionViewDataSource>
{
    UICollectionView *_CollectionV;
    SubjectThreeLightCell *_cell;
    UIView *header;
}
@end

@implementation SubjectThreeLightSetViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    self.view.backgroundColor = [UIColor whiteColor];
    //隐藏头部view
    self.navigationController.navigationBar.hidden = YES;
    NavigationHeadView *navgationheadv = [[NavigationHeadView alloc]initWithFrame:CGRectMake(0, 0, APPwidth, SafeAreaTopHight)];
    navgationheadv.titlelabel.text = @"科三灯光设置";
    navgationheadv.titlelabel.textColor = [UIColor blackColor];
    navgationheadv.backbtn.hidden = NO;
    navgationheadv.rightbtn.hidden = NO;
    [navgationheadv.rightbtn setTitle:@"编辑" forState:0];
    [navgationheadv.rightbtn setTitleColor:rgba(22, 120, 255, 1) forState:0];
    [navgationheadv.rightbtn addTarget:self action:@selector(setBtnClick) forControlEvents:UIControlEventTouchUpInside];
    [navgationheadv.backbtn addTarget:self action:@selector(returnback) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:navgationheadv];
    
    [self instructionHead];
    
}
-(void)instructionHead{
    
       UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc]init];
    
    _CollectionV = [[UICollectionView alloc]initWithFrame:CGRectMake(0, SafeAreaTopHight, APPwidth, APPheight-SafeAreaTopHight-50-SafeAreaBottomHeight) collectionViewLayout:layout];
        //设置每一个item的尺寸
        layout.itemSize = CGSizeMake((APPwidth - 50)/2, 175);
       //设置最小行间距
       layout.minimumLineSpacing = 20;
       //设置item与item之间的间距
       layout.minimumInteritemSpacing = 10;
       layout.sectionInset = UIEdgeInsetsMake(10, 10, 10, 10);
       //设置滑动方向
       layout.scrollDirection = UICollectionViewScrollDirectionVertical;
       _CollectionV.dataSource = self;
       _CollectionV.delegate = self;
       //集合视图如果想要显示内容，必须要将cell进行注册
        [_CollectionV registerClass:[SubjectThreeLightCell class] forCellWithReuseIdentifier:@"cell"];
        [_CollectionV registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:headidentifir];
       //给头视图布局
       layout.headerReferenceSize = CGSizeMake(APPwidth, 80);

        [self.view addSubview:_CollectionV];
    
    
    UIButton *bottomBtn = [[UIButton alloc]initWithFrame:CGRectMake(0, APPheight-SafeAreaBottomHeight-50, APPwidth, 50)];
    [bottomBtn setTitle:@"随机播放5条单项指令" forState:0];
    bottomBtn.contentHorizontalAlignment = 1;
    [bottomBtn setBackgroundColor:[UIColor whiteColor]];
    [bottomBtn setTitleColor:rgba(51, 51, 51, 1) forState:0];
    bottomBtn.titleEdgeInsets = UIEdgeInsetsMake(0, 15, 0, 0);
    bottomBtn.layer.shadowPath = [UIBezierPath bezierPathWithRect:bottomBtn.bounds].CGPath;
    bottomBtn.titleLabel.font = [UIFont boldSystemFontOfSize:14];
    bottomBtn.layer.shadowColor = [UIColor grayColor].CGColor;
    bottomBtn.layer.shadowRadius = 1;
    bottomBtn.layer.shadowOpacity = 0.5;
    //    bmBtn.imageEdgeInsets = UIEdgeInsetsMake(10, 13, 7, 62);
    //    [bmBtn.imageView setContentMode:UIViewContentModeScaleAspectFit];
    //    bmBtn.titleEdgeInsets = UIEdgeInsetsMake(0, 13, 0, 0);
    [self.view addSubview:bottomBtn];
    
    UIButton *bfBtn = [[UIButton alloc]initWithFrame:CGRectMake(bottomBtn.width-100,15, 60, 30)];
    [bfBtn setTitle:@"播放" forState:0];
    bfBtn.contentHorizontalAlignment = 0;
    [bfBtn setBackgroundColor:rgba(22, 120, 255, 1)];
    [bfBtn setTitleColor:[UIColor whiteColor] forState:0];
    bfBtn.titleLabel.font = [UIFont systemFontOfSize:13];
    bfBtn.layer.cornerRadius = 15;
    [bottomBtn addSubview:bfBtn];
    
    
    
    
    
}

-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    return 1;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return 10;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    
  _cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];

//    _cell.contentView.backgroundColor = rgba(245, 245, 250, 1);
    _cell.layer.cornerRadius = 8;
    return _cell;
}
- (UICollectionReusableView*)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath{
    if ([kind isEqualToString:UICollectionElementKindSectionHeader]) {
        UICollectionReusableView *head = [collectionView dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:headidentifir forIndexPath:indexPath];
        [self addhead];
        [head addSubview:header];
        return head;

    }
    return nil;
}
-(void)addhead{
    header = [[UIView alloc]initWithFrame:CGRectMake(0, 0, APPwidth, 80)];
    header.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:header];

    NSArray *OrderArr = @[@"组合指令",@"单项指令"];
    for (int i = 0; i < OrderArr.count; i++) {
        UIButton *orderBtn = [[UIButton alloc]initWithFrame:CGRectMake(APPwidth/2*i + APPwidth/38 *(5-3*i), 15, APPwidth/19 *6, 45)];
        [orderBtn setTitle:OrderArr[i] forState:0];
        [orderBtn setBackgroundColor:rgba(226, 239, 255, 1)];
        orderBtn.contentHorizontalAlignment = 0;
        [orderBtn setTitleColor:rgba(51, 51, 51, 1) forState:0];
        orderBtn.titleLabel.font = [UIFont systemFontOfSize:16];
        orderBtn.layer.cornerRadius = 45/2;
        [header addSubview:orderBtn];
    }
    
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    
    NSLog(@"didselected = %lu",indexPath.row);
}

#pragma mark - 设置
-(void)setBtnClick{
    CustomDirectiveViewController *vc = [[CustomDirectiveViewController alloc]init];
    [self.navigationController pushViewController:vc animated:YES];
}

-(void)returnback{
    [self.navigationController popViewControllerAnimated:YES];
}
#pragma mark -视图即将出现
-(void)viewWillAppear:(BOOL)animated{
        
    ((TabbarController *)self.tabBarController).tabBarView.hidden = YES;
    
}



@end
